$(document).ready(function(){
	cw.common.setStyle();
	$('#subImg').bind('click',subButton);
	//cw.common.getUserSession(loadRoleTree,true);
	validate();
	queryPERSONNAL();
	$("#CHANGE_DATE").focus(function(){WdatePicker({dateFmt:'yyyy-MM-dd',oncleared:function(){$(this).blur();},onpicked:function(){$(this).blur();}})});
	$("#CHANGE_DATE").val(tody);
})

function subFrm(){
	var options = {
	    dataType: 'json',
    	iframe:	false,
	    success: function(data) {
	    	if(data.success){
	    		alert("资产维修成功!");
	    		$('#subImg').unbind('click',subButton);
	    		var id=$("#ID").val();
	    		$("#buttonCentent").append('<a href="../check/print_godown_entry_detail.html?ID='+id+'&STATUS=2" target="_blank"><img src="../images/anniu32.gif" style="cursor: hand;"/></a>');
	      	}else{
	      		alert(data.errors.errmsg);
	      	}
	   	}
	};
	$.ajaxSetup({contentType:'application/x-www-form-urlencoded;charset=utf-8'});
    $('#frm').ajaxSubmit(options);
}

function subButton(){
	$('#subImg').unbind('click',subButton);
	return jQuery.formValidator.pageIsValid(1);
}

function validate(){
	$.formValidator.initConfig({formid:"frm",onerror:function(msg){$('#subImg').bind('click',subButton);alert(msg);},onsuccess:function(){subFrm();return false;}});
	
	$("#REMARK").formValidator({empty:true,onshow:"请输入用户备注",oncorrect:"正确",onfocus:"请输入用户备注信息"}).inputValidator({max:400,onerror:"用户备注信息中文不超过200个字，英文不超过300个字符"});
	$("#AFTER_PRICE").formValidator({onshow:"请输入维修价格",oncorrect:"正确",onfocus:"请输入维修价格"}).regexValidator({regexp:"num",datatype:"enum",onerror:"您输入的价格不正确"});
	$("#CHAGE_REASON").formValidator({empty:true,onshow:"请输入维修原因",oncorrect:"正确",onfocus:"请输入维修原因"}).inputValidator({max:400,onerror:"维修原因中文不超过200个字，英文不超过300个字符"});
	$("#PERSON").formValidator({onshow:"请选择维修负责人",onfocus:"请选择维修负责人"}).inputValidator({min:1,onerror: "请选择维修负责人"});
}

